package com.unohacha.qqj.fzdr.main;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.google.gson.Gson;
import com.huangmin66.rongcloud.RongCloudUtils;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.unohacha.qqj.fzdr.R;
import com.unohacha.qqj.fzdr.adapter.BaseRVAdapter;
import com.unohacha.qqj.fzdr.adapter.BaseViewHolder;
import com.unohacha.qqj.fzdr.bean.ShareInfo;
import com.unohacha.qqj.fzdr.bean.find.FindDetailBean;
import com.unohacha.qqj.fzdr.bean.find.RongInfoBean;
import com.unohacha.qqj.fzdr.imp.MyApplication;
import com.unohacha.qqj.fzdr.imp.MyCallBack;
import com.unohacha.qqj.fzdr.imp.UrlConfig;
import com.unohacha.qqj.fzdr.imp.XUtil;
import com.unohacha.qqj.fzdr.util.FastUtils;
import com.unohacha.qqj.fzdr.util.GlideImageLoader;
import com.unohacha.qqj.fzdr.util.Prefer;
import com.unohacha.qqj.fzdr.view.MyRecyclerView;
import com.unohacha.qqj.fzdr.view.ObservableScrollView;
import com.unohacha.qqj.fzdr.view.ShareDialog;
import com.unohacha.qqj.mylibrary.base.BaseActivity;
import com.unohacha.qqj.mylibrary.listener.PoponDismissListener;
import com.unohacha.qqj.mylibrary.view.CommentPopWindow;
import com.unohacha.qqj.mylibrary.view.ConfirmPopWindow;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerListener;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import io.rong.imkit.RongIM;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.UserInfo;

/**
 * 发现列表详情  item_comment_list  详细资料列表 item_detail_ifo
 */
public class FindDetailActivity2 extends BaseActivity {


    @BindView(R.id.common_back)
    ImageView commonBack;
    @BindView(R.id.common_title)
    TextView commonTitle;
    @BindView(R.id.common_right_image)
    ImageView commonRightImage;
    @BindView(R.id.common_right_text)
    TextView commonRightText;
    @BindView(R.id.home1_title)
    LinearLayout home1Title;
    @BindView(R.id.banner)
    Banner banner;
    @BindView(R.id.store_logo_iv)
    ImageView storeLogoIv;
    @BindView(R.id.store_name_tv)
    TextView storeNameTv;
    @BindView(R.id.store_report_content)
    TextView storeReportContent;
    @BindView(R.id.report_time_tv)
    TextView reportTimeTv;
    @BindView(R.id.content_detail)
    TextView contentDetail;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.detail_ll)
    LinearLayout detailLl;
    @BindView(R.id.mRecyclerView)
    MyRecyclerView mRecyclerView;
    @BindView(R.id.other_ll)
    LinearLayout otherLl;
    @BindView(R.id.bg_view)
    View bg_view;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.look_more_tv)
    TextView lookMoreTv;
    @BindView(R.id.comment_ll)
    RelativeLayout commentLl;
    @BindView(R.id.comment_rv)
    RecyclerView commentRv;
    @BindView(R.id.contact_ll)
    RelativeLayout contactLl;
    @BindView(R.id.collection_ll)
    RelativeLayout collectionLl;
    @BindView(R.id.send_ll)
    LinearLayout sendLl;
    @BindView(R.id.comment_ll_0)
    LinearLayout comment_ll_0;
    @BindView(R.id.collection_tv)
    TextView collectionTv;
    @BindView(R.id.comment_tv)
    TextView commentTv;
    @BindView(R.id.send_tv)
    TextView sendTv;
    @BindView(R.id.collection_iv)
    ImageView collection_iv;
    @BindView(R.id.comment_list_ll)
    LinearLayout comment_list_ll;
    @BindView(R.id.store_pic)
    ImageView store_pic;
    @BindView(R.id.user_name_tv)
    TextView user_name_tv;
    @BindView(R.id.user_report_content)
    TextView user_report_content;
    @BindView(R.id.comment_user)
    TextView comment_user;
    @BindView(R.id.contact_tv)
    TextView contact_tv;
    @BindView(R.id.scrollView)
    ObservableScrollView scrollView;
    private int imageHeight;


    private List<String> mDetailInfoList = new ArrayList<>();//banner的集合
    private List<String> mBannerList = new ArrayList<>();
    private int typeid;//从列表界面传过来的
    private int typeID;
    private int id;
    private String type;//类型 
    private String[] mList;//详情资料
    private Map<String,String> mDetailMap = new HashMap<>(); 
    private String supply_cate_id_id;
    private ShareDialog shareDialog;
    private String phoneNum;
    private static final int MY_PERMISSIONS_REQUEST_CALL_PHONE = 10088;
    private String targetId;
    private String title;
    private String thumb;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_find_detail2;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setText("供应详情");
        commonRightImage.setVisibility(View.VISIBLE);
        commonRightText.setVisibility(View.GONE);
        commonRightImage.setImageResource(R.drawable.ic_bg_share);
        commonBack.setImageResource(R.drawable.ic_bg_back);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        
        commentRv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

        if (null != getIntent()) {
            typeid = getIntent().getIntExtra("typeid", 0);
            typeID = typeid;
            id = getIntent().getIntExtra("id", 0);
            getSupplyDetailData(id, typeid);
        }

        initListeners();
       
    }

    private void setDetailInfoList() {
        int ecosphere = Prefer.getInstance().getEcosphere();
        if (ecosphere == 1) {
            mList = getResources().getStringArray(R.array.ml_type);
        } else if (ecosphere == 2) {
            mList = getResources().getStringArray(R.array.zz_type);
        } else if (ecosphere == 3) {
            mList = getResources().getStringArray(R.array.yl_type);
        } else if (ecosphere == 4) {//招聘
            
        } else if (ecosphere == 5) {//求职
            mList = getResources().getStringArray(R.array.find_job);
        } else if (ecosphere == 6) {//租赁
            mList = getResources().getStringArray(R.array.zulin);
        } else if (ecosphere == 7) {//设备
            mList = getResources().getStringArray(R.array.shebei);
        } else if (ecosphere == 8) {//维修

        } else if (ecosphere == 9) {//库存
            mList = getResources().getStringArray(R.array.kucun);
        } else if (ecosphere == 10) {//辅料
            mList = getResources().getStringArray(R.array.fuliao);
        } else if (ecosphere == 11) {//处理
            mList = getResources().getStringArray(R.array.chuli);
        } else if (ecosphere == 12) {//其他供求
            mList = getResources().getStringArray(R.array.other);
        }

        for (int i = 0; i < mList.length; i++) {
            mDetailInfoList.add(i, mList[i]);
        }

        if (null != mDetailInfoList) {
            setDetailInfoAdapter();
        }
    }

    //设置资料详情数据
    private void setDetailInfoAdapter() {
        BaseRVAdapter mBaseAdapter = new BaseRVAdapter(this, mDetailInfoList) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_detail_info;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {
                TextView item_name = holder.getTextView(R.id.item_name);
                TextView item_content = holder.getTextView(R.id.item_content);
                item_name.setText(mDetailInfoList.get(position));
                if (mDetailInfoList.get(position).contains("型号")){
                    if (!TextUtils.isEmpty(mDetailMap.get("fabric_model")))
                        item_content.setText(mDetailMap.get("fabric_model"));
                    else
                        item_content.setText(mDetailMap.get("model_number"));
                } else if (mDetailInfoList.get(position).contains("量单位")) {
                    item_content.setText(mDetailMap.get("nums_company"));
                } else if (mDetailInfoList.get(position).contains("价单位")) {
                    item_content.setText(mDetailMap.get("price_company"));
                } else if (mDetailInfoList.get(position).contains("年份")) {
                    item_content.setText(mDetailMap.get("factory_time"));
                } else if (mDetailInfoList.get(position).contains("产地")) {
                    item_content.setText(mDetailMap.get("producing_area"));
                } else if (mDetailInfoList.get(position).contains("数量")){
                    item_content.setText(mDetailMap.get("nums"));
                }else if (mDetailInfoList.get(position).contains("单价")){
                    item_content.setText(mDetailMap.get("price"));
                }else if (mDetailInfoList.get(position).contains("幅宽")){
                    item_content.setText(mDetailMap.get("breadth") + " " + mDetailMap.get("breadth_company"));
                }else if (mDetailInfoList.get(position).contains("工艺")){
                    item_content.setText(mDetailMap.get("technology"));
                }else if (mDetailInfoList.get(position).contains("成分")){
                    item_content.setText(mDetailMap.get("component"));
                }else if (mDetailInfoList.get(position).contains("克重")){
                    item_content.setText(mDetailMap.get("gram_weight") + " " + mDetailMap.get("gram_weight_company"));
                }else if (mDetailInfoList.get(position).contains("规格")){
                    if (!TextUtils.isEmpty(mDetailMap.get("spec"))) {
                        item_content.setText(mDetailMap.get("spec"));
                    }else {
                        item_content.setText(mDetailMap.get("spec_company"));
                    }
                } else if (mDetailInfoList.get(position).contains("扣幅")) {
                    item_content.setText(mDetailMap.get("breadth"));
                } else if (mDetailInfoList.get(position).contains("针纹")) {
                    item_content.setText(mDetailMap.get("pointer_loom") + "针");
                } else if (mDetailInfoList.get(position).contains("循环")) {
                    item_content.setText(mDetailMap.get("flower_nums"));
                } else if (mDetailInfoList.get(position).contains("经轴")) {
                    item_content.setText(mDetailMap.get("multi_beam"));
                }
            }
        };
        mRecyclerView.setAdapter(mBaseAdapter);
        mBaseAdapter.notifyDataSetChanged();
    }

    @OnClick({R.id.common_back, R.id.common_right_image,
            R.id.collection_ll,R.id.comment_ll_0,R.id.look_more_tv,
            R.id.contact_ll,R.id.send_ll})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.common_back:
                finish();
                break;
            case R.id.common_right_image:
//                ToastUtils.showT("功能升级中...");
                ShareInfo shareInfo = new ShareInfo();
                shareInfo.title = "纺织达人";
                shareInfo.text = "纺织达人 - 让天下没有难找的纺织信息!";
                shareInfo.targetUrl = "http://huafangcs.unohacha.com";
                shareInfo.imgUrl = "http://huafang.unohacha.com//uploads//admin//admin_thumb//20180619//6542e1b6d83980735c8d41a53293ad58.jpg";
                
                shareDialog = new ShareDialog(FindDetailActivity2.this, shareInfo, null, new UMShareListener() {
                    @Override
                    public void onStart(SHARE_MEDIA share_media) {

                    }

                    @Override
                    public void onResult(SHARE_MEDIA share_media) {
                        Toast.makeText(FindDetailActivity2.this, "分享成功", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onError(SHARE_MEDIA share_media, Throwable t) {
                        Toast.makeText(FindDetailActivity2.this, "分享失败", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onCancel(SHARE_MEDIA share_media) {
                        Toast.makeText(FindDetailActivity2.this, "分享取消", Toast.LENGTH_SHORT).show();
                    }
                });
                shareDialog.show();
                break;
            case R.id.collection_ll:
                 icCollection(typeid,id);
                break;
            case R.id.comment_ll_0://写评论
                if (null == commentPopWindow){
                    commentPopWindow = new CommentPopWindow(FindDetailActivity2.this,FindDetailActivity2.this);
                }
                commentPopWindow.showUi("写评论","取消","发布");
                commentPopWindow.showAtLocation(comment_ll_0, Gravity.CENTER,0,0);
                handler.sendEmptyMessage(1001);
                commentPopWindow.setConfirmListener(new CommentPopWindow.OnCommentListener() {
                    @Override
                    public void onSure(String content) {
                        //发布评论，同时刷新供应详情信息
                        if (!TextUtils.isEmpty(content) && !TextUtils.isEmpty(supply_cate_id_id) ) {
                            supplyComments(1,supply_cate_id_id,"",content);
                        }else {
                            MyToast("请输入评论内容!");
                            return;
                        }
                    }

                    @Override
                    public void onCancel() {
                        MyToast("取消");
                        commentPopWindow.dismissView();
                    }
                });
                commentPopWindow.setOnDismissListener(new PoponDismissListener(this));
                break;
            case R.id.look_more_tv://查看更多评论
                Intent intent = new Intent(FindDetailActivity2.this,AllCommentsActivity.class);
                intent.putExtra("supply_cate_id",supply_cate_id_id);
                intent.putExtra("supply_id",id + "");
                startActivity(intent);
                break;
            case R.id.contact_ll://打电话
                phoneNum = contact_tv.getText().toString().trim();
                callPhone();
                break;
            case R.id.send_ll://发送消息
                title = storeNameTv.getText().toString().trim();
                RongCloudUtils.getInstance().startConversation(FindDetailActivity2.this, Conversation.ConversationType.PRIVATE,targetId,title);
               
                getMyNews();
                break;
        }
    }

    //实现标题栏随滚动的显示和隐藏
    private void initListeners() {
        // 获取顶部图片高度后，设置滚动监听
        ViewTreeObserver vto = banner.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                banner.getViewTreeObserver().removeGlobalOnLayoutListener(
                        this);
                imageHeight = banner.getHeight();
                scrollView.setScrollViewListener(new ObservableScrollView.ScrollViewListener() {
                    @Override
                    public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
                        // TODO Auto-generated method stub
                        // Log.i("TAG", "y--->" + y + "    height-->" + height);
                        if (y <= 0) {
//                          设置文字背景颜色，白色
                            home1Title.setBackgroundColor(Color.argb((int) 0, 255, 255, 255));//AGB由相关工具获得，或者美工提供
//                          设置文字颜色，黑色
                            commonTitle.setTextColor(Color.argb((int) 0, 255, 255, 255));
                            Log.e("111","y <= 0");
                        } else if (y > 0 && y <= imageHeight) {

                            float scale = (float) y / imageHeight;
                            float alpha = (255 * scale);
                            // 只是layout背景透明(仿知乎滑动效果)白色透明
                            home1Title.setBackgroundColor(Color.argb((int) alpha, 255, 255, 255));
                            //                          设置文字颜色，黑色，加透明度
                            commonTitle.setTextColor(Color.argb((int) alpha, 0, 0, 0));
                            Log.e("111","y > 0 && y <= imageHeight");
                        } else {
//							白色不透明
                            home1Title.setBackgroundColor(Color.argb((int) 255, 255, 255, 255));
                            //                          设置文字颜色
                            //黑色
                            commonTitle.setTextColor(Color.argb((int) 255, 0, 0, 0));
                            Log.e("111","else");
                        }

                    }
                });

            }
        });


    }

    private void callPhone(){//打电话
        if (!FastUtils.isFastDoubleClick()){
            if (!TextUtils.isEmpty(phoneNum)){

                if (null == confirmPop){
                    confirmPop =  new ConfirmPopWindow(FindDetailActivity2.this,FindDetailActivity2.this);
                }
                confirmPop.showUi("是否拨打" + phoneNum,"取消","确定");
                confirmPop.showAtLocation(contactLl, Gravity.CENTER,0,0);
                confirmPop.setConfirmListener(new ConfirmPopWindow.OnConfirmListener() {
                    @Override
                    public void onSure() {

                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
                                && ContextCompat.checkSelfPermission(FindDetailActivity2.this,
                                Manifest.permission.CALL_PHONE)
                                != PackageManager.PERMISSION_GRANTED) {
                            ActivityCompat.requestPermissions(FindDetailActivity2.this,
                                    new String[]{Manifest.permission.CALL_PHONE},
                                    MY_PERMISSIONS_REQUEST_CALL_PHONE);
                        } else {
                            Intent intent2 = new Intent(Intent.ACTION_DIAL);
                            Uri data = Uri.parse("tel:" + phoneNum);
                            intent2.setData(data);
                            startActivity(intent2);
                        }
                    }

                    @Override
                    public void onCancel() {
                        confirmPop.dismissView();
                    }
                });
                confirmPop.setOnDismissListener(new PoponDismissListener(FindDetailActivity2.this));
            }
        }
    }
    
    Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            //在需要弹出软键盘的地方发送msg
            if (msg.what==1001){
                //使用以下代码来弹出软键盘
                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    //设置banner 数据
    private void setBannerData() {
        if (null != mBannerList) {
            banner.setVisibility(View.VISIBLE);
            banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);//设置圆形指示器与标题
            banner.setIndicatorGravity(BannerConfig.CENTER);//设置指示器位置
            banner.setImages(mBannerList);
            banner.setImageLoader(new GlideImageLoader());
            banner.start();

            banner.setOnBannerListener(new OnBannerListener() {
                @Override
                public void OnBannerClick(int position) {
                    //用mBannerAllList集合
                }
            });
        }else {
            banner.setVisibility(View.GONE);
        }
    }

//    //加载圆形头像
//            Glide.with(getActivity()).load(item.getMember_thumb())
//            .asBitmap().centerCrop().into(new BitmapImageViewTarget(imgHead) {
//        @Override
//        protected void setResource(Bitmap resource) {
//            RoundedBitmapDrawable circularBitmapDrawable =
//                    RoundedBitmapDrawableFactory.create(getActivity().getResources(), resource);
//            circularBitmapDrawable.setCircular(true);
//            imgHead.setImageDrawable(circularBitmapDrawable);
//        }
//    });
    //获取供求详情数据 
    private void getSupplyDetailData(int id, int supply_cate_id) {
        showLoading();
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        params.put("supply_cate_id", supply_cate_id);
        params.put("address_id", Prefer.obtainReLocation(this));
        params.put("token", Prefer.getInstance().getToken());
        XUtil.Post(UrlConfig.SUPPLY_DETAIL, params, new MyCallBack<String>() {

            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Log.e("TAG: result: " ,result);
                try {
                    Gson gson = new Gson();
                    FindDetailBean  findDetailBean = gson.fromJson(result, FindDetailBean.class);
                    JSONObject jsonObject = new JSONObject(result);
                    if (1 == jsonObject.optInt("code")) {
                        if (null != findDetailBean) {
                            //加载圆形头像
                                Glide.with(FindDetailActivity2.this).load(findDetailBean.getData().getMember_thumb())
                                .asBitmap().centerCrop().error(R.drawable.ic_default_photo).into(new BitmapImageViewTarget(storeLogoIv) {
                                    @Override
                                    protected void setResource(Bitmap resource) {
                                        RoundedBitmapDrawable circularBitmapDrawable =
                                                RoundedBitmapDrawableFactory.create(getResources(), resource);
                                        circularBitmapDrawable.setCircular(true);
                                        storeLogoIv.setImageDrawable(circularBitmapDrawable);
                                    }
                                });
//                            Glide.with(FindDetailActivity2.this)
//                                    .load(findDetailBean.getData().getMember_thumb())
//                                    .error(R.drawable.ic_default_photo).into(storeLogoIv);
                            targetId = findDetailBean.getData().getMember_id() + "";
                            thumb = findDetailBean.getData().getMember_thumb();
                            storeNameTv.setText(findDetailBean.getData().getMember_no());
                            contentDetail.setText(findDetailBean.getData().getTitle());
                            storeReportContent.setText(findDetailBean.getData().getCreate_time() + "发布");
                            tvType.setText("分类：" + findDetailBean.getData().getSupply_cate_id());
                            contact_tv.setText(findDetailBean.getData().getMember_tel());
                            supply_cate_id_id = findDetailBean.getData().getSupply_cate_id_id() + "";
                            if (TextUtils.isEmpty(findDetailBean.getData().getContent())) {
                                otherLl.setVisibility(View.GONE);
                                bg_view.setVisibility(View.GONE);
                                tvContent.setVisibility(View.GONE);
                            } else
                                tvContent.setText(findDetailBean.getData().getContent());
                            if (1 == findDetailBean.getData().getComm_num()){//有评价
                                comment_list_ll.setVisibility(View.VISIBLE);
                                Glide.with(FindDetailActivity2.this).
                                        load(findDetailBean.getData().getComm_member_thumb())
                                        .error(R.drawable.ic_default_photo).into(store_pic);
                                user_name_tv.setText(findDetailBean.getData().getComm_member_no());
                                user_report_content.setText(findDetailBean.getData().getComm_create_time());
                                comment_user.setText(findDetailBean.getData().getComm_content());

                            }else {//没有评价
                                comment_list_ll.setVisibility(View.GONE);
                            }
                            if (findDetailBean.getData().getIs_collection() == 0) {//未收藏
                                collection_iv.setImageResource(R.drawable.ic_like);
                                collectionTv.setText("未收藏");
                                collectionTv.setTextColor(getResources().getColor(R.color.text_black_666));

                            } else {
                                collection_iv.setImageResource(R.drawable.ic_like_after);
                                collectionTv.setText("已收藏");
                                collectionTv.setTextColor(getResources().getColor(R.color.text_color_red));

                            }

                            Log.e("TAG: getCollection",findDetailBean.getData().getCollection()+"");
                            if (null != mBannerList) {
                                mBannerList.clear();
                            }
                            mBannerList.addAll(findDetailBean.getData().getList_pic());
                            setBannerData();
                            type = findDetailBean.getData().getSupply_cate_id();
                            Log.e("TAG, type", type);
                            if (0 != mDetailMap.size()){
                                mDetailMap.clear();
                            }
                            mDetailMap.put("nums",findDetailBean.getData().getNums() + "");//数量
                            mDetailMap.put("nums_company",findDetailBean.getData().getNums_company());//数量单位
                            mDetailMap.put("price",findDetailBean.getData().getPrice());//价格
                            mDetailMap.put("msg",findDetailBean.getData().getMsg());//剩余天数提示语
                            mDetailMap.put("price_company",findDetailBean.getData().getPrice_company());//价格单位
                            mDetailMap.put("breadth",findDetailBean.getData().getBreadth());//幅宽
                            mDetailMap.put("breadth_company",findDetailBean.getData().getBreadth_company());//幅宽单位
                            mDetailMap.put("technology",findDetailBean.getData().getTechnology());//工艺
                            mDetailMap.put("gram_weight",findDetailBean.getData().getGram_weight());//克重
                            mDetailMap.put("gram_weight_company",findDetailBean.getData().getGram_weight_company());//克重单位
                            mDetailMap.put("component",findDetailBean.getData().getComponent());//成分
                            mDetailMap.put("fabric_model",findDetailBean.getData().getFabric_model());//型号
                            mDetailMap.put("model_number",findDetailBean.getData().getMember_no());//型号
                            mDetailMap.put("producing_area",findDetailBean.getData().getProducing_area());//产地
                            mDetailMap.put("factory_time",findDetailBean.getData().getFactory_time());//时间
                            mDetailMap.put("breadth",findDetailBean.getData().getBreadth());//织机扣幅
                            mDetailMap.put("pointer_loom",findDetailBean.getData().getPointer_loom());//织机针纹
                            mDetailMap.put("flower_nums",findDetailBean.getData().getFlower_nums());//织机循环
                            mDetailMap.put("multi_beam",findDetailBean.getData().getMulti_beam());//是否多经轴
                            if (!TextUtils.isEmpty(findDetailBean.getData().getSpec())){
                                mDetailMap.put("spec",findDetailBean.getData().getSpec());
                            }
                            if (!TextUtils.isEmpty(findDetailBean.getData().getSpec_company())){
                                mDetailMap.put("spec_company",findDetailBean.getData().getSpec_company());
                            }
                            setDetailInfoList();
                        }
                    } else if (100 == jsonObject.optInt("code")) {
                        MyToast(getResources().getString(R.string.login_out));
                        MyApplication.getInstance().gotoLoginActivity();
                    } else {
                        MyToast(jsonObject.optString("message"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                super.onFinished();
                hideLoading();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                hideLoading();
            }
        });
    }

    //供求评价
    private void supplyComments(int typeid,String supply_cate_id,String pid,String content){
        Map<String,Object> params = new HashMap<>();
        params.put("token",Prefer.getInstance().getToken());
        params.put("typeid",typeid);
        params.put("supply_cate_id",supply_cate_id);
        params.put("supply_id",id);
        params.put("pid",pid);
        params.put("content",content);
        XUtil.Post(UrlConfig.SUPPLY_COMMENTS,params,new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    if (1 == jsonObject.optInt("code")){
                        getSupplyDetailData(id, typeID);
                    }else if (100 == jsonObject.optInt("code")){
                        MyToast(getResources().getString(R.string.login_out));
                        MyApplication.getInstance().gotoLoginActivity();
                    }
                    MyToast(jsonObject.optString("message"));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
            }
        });
    }

    //获取个人信息
    private void getMyNews(){
        Map<String,Object> params = new HashMap<>();
        params.put("id",targetId);
        XUtil.Post(UrlConfig.MY_NEW_INFO,params,new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    if (1 == jsonObject.optInt("code")){
                        Gson gson = new Gson();
                        RongCloudUtils.getInstance()
                                .setCurrentUserInfo(new UserInfo(targetId, storeNameTv.getText().toString().trim(), Uri.parse(thumb)));
                    }else if (100 == jsonObject.optInt("code")){
                        MyToast(getResources().getString(R.string.login_out));
                        MyApplication.getInstance().gotoLoginActivity();
                    }else {
                        MyToast(jsonObject.optString("message"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
            }
        });
    }
    
    
    //收藏取消收藏  SUPPLY_COLLECTION
    private void icCollection(int supply_cate_id, int supply_id) {
        showLoading();
        Map<String, Object> params = new HashMap<>();
        params.put("token", Prefer.getInstance().getToken());
        params.put("supply_cate_id", supply_cate_id);
        params.put("supply_id", supply_id);
        XUtil.Post(UrlConfig.SUPPLY_COLLECTION, params, new MyCallBack<String>() {
            @SuppressLint("NewApi")
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);

                try {

                    Log.e("TAG: icCollection",result);
                    JSONObject jsonObject = new JSONObject(result);

                    if (1 == jsonObject.optInt("code")){
                        if (jsonObject.optString("message").contains("收藏")){
                        collection_iv.setImageResource(R.drawable.ic_like_after);
                        collectionTv.setText("已收藏");
                        collectionTv.setTextColor(getResources().getColor(R.color.text_color_red));
                        }else {
                        collection_iv.setImageResource(R.drawable.ic_like);
                        collectionTv.setText("未收藏");
                        collectionTv.setTextColor(getResources().getColor(R.color.text_black_666));
                        }
                    }else if (100 == jsonObject.optInt("code")){
                        MyToast(getResources().getString(R.string.login_out));
                        MyApplication.getInstance().gotoLoginActivity();
                    }

                    MyToast(jsonObject.optString("message"));

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                super.onFinished();
                hideLoading();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                hideLoading();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
